package com.hystrix.command;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandProperties;

/**
 * 测试断路器开启。模拟超时命令
 */
public class OpenCommand extends HystrixCommand<String> {



    public OpenCommand() {
        // 设置超时的时间为500毫秒
        super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"))
                .andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
                        .withExecutionTimeoutInMilliseconds(500))
        );
    }

    @Override
    protected String run() throws Exception {
        // 模拟处理超时，故意设置800秒超时
        Thread.sleep(800);
        return "";
    }

    @Override
    protected String getFallback() {
        return "";
    }
}
